package com.niit.controller;

import com.niit.pojo.Student;
import com.niit.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentController {

    /*因为add需要使用service，所以要把studentsservice注入并自动装配*/
    @Autowired
    private StudentService studentService;

    @RequestMapping("/index")
    public String index(){
        System.out.println(1);
        return "index";
    }

    @PostMapping("/addStudent")
    @ResponseBody
    public String addStudent(Student student){
        int i= studentService.addStudent(student);
        if(i>0)
            return "index";
        else
            return "保存失败";

    }
}
